package iedcyt.acute.controller.listeners.authorMerge;

import iedcyt.acute.businessServices.cache.domain.ReviewAuthor;
import iedcyt.acute.model.AuthorFilterCode;
import iedcyt.acute.model.AuthorMergeModel;

import iedcyt.acute.view.AuthorMergeView;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TableItem;

public class SearchAuthorTxtKeyDownListener extends AuthorMergeCommonListener implements Listener {


	
	public SearchAuthorTxtKeyDownListener(AuthorMergeView view,
			AuthorMergeModel model) {
		super(view, model);
		this.toolTip = "";
	}

	public void handleEvent(Event event) {

		// Al pulsar 'Intro' se lanza la busqueda de autor
		if (event.character == '\r') {
			_model.setSearch(_view.getSearchText());
			_model.setFilterCode(AuthorFilterCode.FILTER_SEARCH);
			
			_view.loadAuthors(_model.getAuthors());
			_view.loadCandidateAuthors(_model.getCandidates());
			_view.loadAuthorDocuments(_model.getAuthorDocs());
			_view.loadCandidateDocuments(_model.getCandidateDocs());
			_view.loadAuthorCenters(_model.getAuthorCenters(), _model.isAuthorCentersWarning());
			_view.loadCandidateCenters(_model.getCandidateCenters(),_model.isCandidatCentersWarning());
			_view.loadAuthorCorps(_model.getAuthorCorps(), _model.isAuthorCorpsWarning());
			_view.loadCandidateCorps(_model.getCandidateCorps(), _model.isCandidateCorpsWarning());
			_view.loadAuthorSigns(_model.getAuthorSigns());
			_view.loadCandidateSigns(_model.getCandidateSigns());
			_view.loadAuthorSignsCollaborators(_model.getAuthorCollSigns());
			_view.loadCandidateSignsCollaborators(_model.getCandidateCollSigns());
			_view.loadAuthorAuthorsCollaborators(_model.getAuthorCollAuthors());
			_view.loadCandidateAuthorsCollaborators(_model.getCandidateCollAuthors());
			_view.setFilterCode(_model.getFilterCode());
			
			_view.compareTables();
		}
	}
}
